<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{:session('cp.cpsysname')}--系统管理平台</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="{:config('webconfig.description');}">
    <meta name="keywords" content="{:config('webconfig.keywords');}">
    <meta name="author" content="runoob">
    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/index.css"/>
    <link rel="stylesheet" href="__STATIC_URL__/static/css/addmchat.css"/>
    <script src="__STATIC_URL__/static/js/jquery-2.1.4.min.js"></script>
    <script src="__STATIC_URL__/static/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

{include file='public/header'/}
<!------------------导航-------------------------->
<section>
    {include file='public/left'/}
    <!--------------------------主要内容区域------------------------------------->
    <div class="content">
        <div class="page-heading">
            <ul class="breadcrumb">
                <li>
                    当前位置是&nbsp;:&nbsp;系统管理
                </li>
                <li class="active" style="color: #02b87f;"> 类别管理</li>
            </ul>
        </div>
        <div class="panel mgr15 mgl15" style="position: relative;">
            <div class="panel-heading addCharts" style="background:#ededed;">添加类别</div>
            <div class="col-sm-12 text-right mgb10" style="position:absolute;right:20px;top:4px;">
                <button data-toggle="modal" data-target="#myModal" type="button" name="Cashier" method="post" action="" class="btn btn-info">添加类别</button>
            </div>
            <table class="table table-hover">
                <thead>
                <tr>
                    <th>#</th>
                    <th>行业级别</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
              {$info}
                </tbody>
            </table>
        </div>
        <include file='Index/footer'/>
    </div>
</section>
<!-- 添加类别模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    添加类别
                </h4>
            </div>
            <div class="modal-body">
                <div class="panel-body">
                    <form class="form-horizontal adminex-form" action="" method="post" id="sysuser"
                          enctype="multipart/form-data">
                        <div class="form-group" id="levelst">
                            <label class="col-sm-2 col-sm-2 control-label">一级类别:</label>
                            <div class="col-lg-10">
                                <select class="form-control input-sm m-bot15 ipt4" name="level" id="leveltop" onchange="showqx()">
                                    <option value="">选择一级类别</option>
                                    <option value="0">新增一级类别</option>
                                    {volist name="level" id="vo"}
                                    {if condition="$vo['parent_id'] eq '0'"}
                                            <option value="{$vo.id}">{$vo.level}</option>
                                    {/if}
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="ferror2" style="display: none;">
                            <label class="col-sm-2 col-sm-2 control-label" id="levellb">二级类别:</label>
                            <div class="col-sm-10">
                                <input type="text" id="level" name="password" class="form-control ipt4">
                                <div id="error2" class="error"></div>
                            </div>
                        </div>
                        <!--<div class="text-center">
                                    <button type="button" onclick="addform()" class="btn btn-primary">添加类别</button>
                                </div>-->
                    </form>
                </div>
            </div>
            <div class="modal-footer" style="border-top:0;">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="addform()">
                    提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<!--修改模态框-->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close cateclose" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel2">
                    级别维护
                </h4>
            </div>
            <div class="modal-body" id="lbinfo">

            </div>
            <div class="modal-footer" style="border-top: 0;">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary"  onclick="xgform()">
                    提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>


<script src="__STATIC_URL__/static/js/commen.js" type="text/javascript" charset="utf-8"></script>
<script>
  $(function () {
      $('.delete').click(function () {
          var leveltop=$(this).attr('data-id');
          $.ajax({
              type: "post",
              url: "{:url('sysconfig/category_rec')}",
              data: {
                  id: leveltop,
              },
              success: function (data) {
                  if (data.code == "0") {
                      alert(data.message);
                      window.location.reload();
                  } else {
                      alert(data.message);
                      window.location.reload();
                  }
              }
          })

      })

  })
    function showqx() {
        var va = $('#leveltop').val();

        if (va == '0') {

            $('#levellb').html('一级类别');
        } else {
            $('#levellb').html('二级类别');
        }
        $('#ferror2').show();

    }
    ;
    function addform() {
        var leveltop = $("#leveltop").val();
        var level = $("#level").val();
        if (leveltop == "") {
            alert("请选择一级类别");
            return false;
        }

        $.ajax({
            type: "post",
            url: "{:url('sysconfig/category_add')}",
            data: {
                parent_id: leveltop,
                level: level,
            },
            success: function (data) {
                if (data.code == "0") {
                    alert("添加成功");
                    window.location.reload();
                } else {
                    alert(data.message);
                    window.location.reload();
                }
            }
        })

    }
    ;


    function xg(id) {
        $('#lbinfo').html('');

        $.ajax({

            type: 'get',
            url: "{:url('sysconfig/category_modify')}",
            data: {
                id: id,
            },

            success: function (data) {
                $('#lbinfo').html(data);
                $("#myModal2").modal('show');
            }

        })

    }

    function xgform() {
        var leveltopxg = $("#leveltopxg").val();
        var levelxg = $("#levelxg").val();
        var idxg = $("#idxg").val();
        if (leveltop == "") {
            alert("请选择一级类别");
            return false;
        }
        /*  alert(leveltopxg);
         alert(levelxg);
         alert(idxg);
         return;*/
        $.ajax({
            type: "post",
            url: "{:url('sysconfig/category_modify')}",
            data: {
                id: idxg,
                parent_id: leveltopxg,
                level: levelxg,
            },
            success: function (data) {
                if (data.code == "0") {
                    alert("修改成功");
                    window.location.reload();
                } else {
                    alert(data.message);
                    window.location.reload();
                }
            }
        })

    }
    ;
</script>
</body>
</html>
